package com.iaz.tech.tools.ai.neuron.exec;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iaz.tech.tools.ai.neuron.runtime.INeuronRuntimeAbility; 
import com.iaz.tech.tools.generator.java.INeuronSourceGenerateAble;
import com.iaz.tech.tools.uml.IUMLNeuronAble;
import com.iaz.tech.tools.uml.behavioral.sequence.impl.NeuronSequence;
import com.iaz.tech.tools.uml.behavioral.usecase.impl.NeuronUseCase;
import com.iaz.tech.tools.uml.relationship.impl.NeuronAggregationsRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronAssociationsRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronExtendRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronGeneralizationsRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronImportRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronIncludeRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronMergeRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronNestingConnectorsRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronNestingsRelationship;
import com.iaz.tech.tools.uml.relationship.impl.NeuronRealizationsRelationship;
import com.iaz.tech.tools.uml.structural.classstruct.impl.NeuronClassStruct;
import com.iaz.tech.tools.uml.structural.pack.impl.NeuronPackage;

/**
 * 神经元代码生成工厂
 */
public class NeuronCodeGeneratorFactory {
    /**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(NeuronCodeGeneratorFactory.class);
    /**
     * 创建代码生成器
     * @param runtime 神经元运行时能力
     * @param uml UML模型
     * @return 代码生成器
     */
    public static INeuronSourceGenerateAble createGenerator(INeuronRuntimeAbility runtime, IUMLNeuronAble uml) {
        INeuronSourceGenerateAble result = null;
        try {

            if (uml == null) {
                throw new Exception("UML模型为空");
            }

            if (uml instanceof NeuronClassStruct) {
                result = new NeuronClassCodeGenerator(runtime);
            } else if (uml instanceof NeuronPackage) {
                result = new NeuronPackageCodeGenerator(runtime);
            } else if (uml instanceof NeuronSequence) {
                result = new NeuronSequenceCodeGenerator(runtime);
            } else if (uml instanceof NeuronUseCase) {
                result = new NeuronUseCaseCodeGenerator(runtime);
            } else if (uml instanceof NeuronAggregationsRelationship) {
                result = new NeuronAggregationsCodeGenerator(runtime);
            } else if (uml instanceof NeuronAssociationsRelationship) {
                result = new NeuronAssociationsCodeGenerator(runtime);
            } else if (uml instanceof NeuronExtendRelationship) {
                result = new NeuronExtendCodeGenerator(runtime);
            } else if (uml instanceof NeuronGeneralizationsRelationship) {
                result = new NeuronGeneralizationsCodeGenerator(runtime);
            } else if (uml instanceof NeuronImportRelationship) {
                result = new NeuronImportCodeGenerator(runtime);
            } else if (uml instanceof NeuronIncludeRelationship) {
                result = new NeuronIncludeCodeGenerator(runtime);
            } else if (uml instanceof NeuronMergeRelationship) {
                result = new NeuronMergeCodeGenerator(runtime);
            } else if (uml instanceof NeuronNestingConnectorsRelationship) {
                result = new NeuronNestingConnectorsCodeGenerator(runtime);
            } else if (uml instanceof NeuronNestingsRelationship) {
                result = new NeuronNestingsCodeGenerator(runtime);
            } else if (uml instanceof NeuronRealizationsRelationship) {
                result = new NeuronRealizationsCodeGenerator(runtime);
            }
        } catch(Exception e){
            logger.error("异常：" + e.getMessage());
        }
        return result;
    }
}
